package spring5;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareParents;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class AspectAdvice {
	// 配置切入点,该方法无方法体,主要为方便同类中其他方法使用此处配置的切入点
	@Pointcut("execution(* spring5.IHello.*(..))")
	public void aspect() {
	}

	@Before("execution(* spring5.IHello.*(..))")
	public void beforeAdvice() {
		System.out.println("BeforeAdvice method starts…");
	}

	@After("aspect()")
	public void afterAdvice() {
		System.out.println("AfterAdvice method return…");

	}

	@AfterReturning("aspect()")
	public void afterReturningAdvice() {
		System.out.println("AfterReturningAdvice method return…");

	}

	@Around("aspect()")
	public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
		System.out.println("AroundAdvice method starts…");
		Object result = joinPoint.proceed();
		System.out.println("AroundAdvice method return…");
		return result;
	}

	@AfterThrowing("aspect()")
	public void afterThrowing() {
		System.out.println("ThrowAdvice afterThrowing …");
	}

	// 引介增强
	@DeclareParents(value = "spring5.HelloSpeaker", defaultImpl = DeclareParentImpl.class)
	private IDeclareParent iDeclareParent;

}
